package com.dong.es.entity.dtocast.base;

import com.dong.es.entity.EsBaseDTO;
import com.dong.es.entity.EsViewDTO;
import com.dong.es.entity.dtocast.DTOCastMethod;
import com.dong.es.entity.searchparam.agg.EsAggsTermsParam;

/**
 * 使用示例：@DTOCastAnno(sort = 930, field = CsmLocDTO.NAME, paramStrs = {"String"} , method = DTOCastTermsAgg.class)
 *
 * @description: terms 聚合参数转换
 * @author: 陈瑞东
 * @create: 2022-10-18 09:35
 */
public class DTOCastTermsAgg extends DTOCastMethod {

    // 字段名
    private String field;
    // 值的类型
    private Class clazz;

    @Override
    protected Integer sizeLimit() {
        return 2;
    }

    @Override
    protected Class[] typeLimit() {
        return new Class[] {String.class, String.class};
    }

    @Override
    protected void doCast(EsViewDTO viewDTO, EsBaseDTO baseDTO) {
        new EsAggsTermsParam(field, clazz).addTo(baseDTO);
    }

    @Override
    protected void load(Object... args) {
        String field = args[0].toString();
        String clazzStr = args[1].toString();

        Class clazz = String.class;
        // 根据文字修改类型
        switch (clazzStr) {
            case "String":
                clazz = String.class;
                break;
            case "Long":
                clazz = Long.class;
                break;
        }

        this.field = field;
        this.clazz = clazz;
    }
}
